package com.gwtgeo.ui.server.handler;

import org.springframework.beans.factory.annotation.Autowired;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import com.google.inject.Inject;
import com.gwtgeo.service.manager.LocationManager;
import com.gwtgeo.ui.server.spring.ActionHandlerBean;
import com.gwtgeo.ui.shared.rpc.RetrieveSelection;
import com.gwtgeo.ui.shared.rpc.RetrieveSelectionResult;

@ActionHandlerBean
public class RetrieveSelectionHandler implements
		ActionHandler<RetrieveSelection, RetrieveSelectionResult> {

	@Autowired
	private LocationManager locationManager;

	@Inject
	public RetrieveSelectionHandler() {
		super();
	}

	@Override
	public RetrieveSelectionResult execute(RetrieveSelection action,
			ExecutionContext context) throws ActionException {
		return new RetrieveSelectionResult(locationManager.findByCoordinates(
				action.getLatitude(), action
						.getLongitude()));
	}

	@Override
	public Class<RetrieveSelection> getActionType() {
		return RetrieveSelection.class;
	}

	@Override
	public void rollback(RetrieveSelection retrieveSelection,
			RetrieveSelectionResult result, ExecutionContext context)
			throws ActionException {
		// TODO PMA20100207 Handle failure.
	}
}
